import 'package:http/http.dart' as http;
import 'dart:convert';
import 'user_response.dart';

class ApiService {
  // static const String baseUrl = "http://127.0.0.1:8000"; //替换为你的服务器地址
  static const String baseUrl = "http://192.168.31.141:8000";  

  static Future<UserResponse?> sendUserData(String name, int age) async {
    final url = Uri.parse("$baseUrl/welcome");

    final response = await http.post(
      url,
      headers: {'Content-Type': 'application/json'},
      body: jsonEncode({'name': name, 'age': age}),
    );

    if (response.statusCode == 200) {
      return UserResponse.fromJson(jsonDecode(response.body));
    } else {
      return null;
    }
  }
}
